<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>

  <!-- 引入react核心库 -->
  <script src="../js/react.development.js"></script>
  <!-- 引入react-dom,用于支持react操作DOM -->
  <script src="../js/react-dom.development.js"></script>
  <!-- 引入babel,用于将jsx转换为js -->
  <script src="../js/babel.min.js"></script>

  <body>
    <!-- 容器 -->
    <div id="app"></div>
  </body>

  <script type="text/babel">
    class MyComponent extends React.Component {
      //提示左侧数据
      showData1 = () => {
        const { input1 } = this;
        alert(input1.value);
      };

      //失去焦点提示数据
      showData2 = () => {
        const { input2 } = this;
        alert(input2.value);
      };

      render() {
        return (
          <div>
            <input
              type="text"
              ref={(c) => {
                this.input1 = c;
              }}
              placeholder="点击按钮提示数据"
            />
            &nbsp;
            <button ref="button" onClick={this.showData1}>
              点我提示左侧数据
            </button>
            &nbsp;
            <input
              type="text"
              ref={(c) => {
                this.input2 = c;
              }}
              onBlur={this.showData2}
              placeholder="失去焦点提示数据"
            />
            &nbsp;
          </div>
        );
      }
    }

    ReactDOM.render(<MyComponent />, document.getElementById("app"));
  </script>
</html>
